package homework.Demo3;

import java.util.ArrayList;

import java.util.Random;


public class Group implements Runnable {
    private ArrayList<String> prizes;

    public Group(ArrayList<String> prizes) {
        this.prizes = prizes;
    }


    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (prizes.isEmpty()) {
                    System.out.println("奖品已经无了");
                    break;

                }
                Random r = new Random();
                int index = r.nextInt(prizes.size());
                String prize = prizes.remove(index);
                System.out.println(Thread.currentThread().getName() + "...抽出了一个：" + prize);
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
